var e = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  t = require("../../../@babel/runtime/helpers/objectSpread2"),
  n = require("../../../@babel/runtime/helpers/regeneratorRuntime"),
  a = require("../../../@babel/runtime/helpers/slicedToArray"),
  r = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  i = require("../../../components/base/m-button/index"),
  d = require("../../../config/index"),
  o = require("../../../utils/index"),
  s = e(require("../behavior")),
  u = o.helper.publish;

function c(e) {
  return l.apply(this, arguments)
}

function l() {
  return (l = r(n().mark((function e(t) {
    var r, i, d, o, s, c, l, m, f, h, p, _, y, b, v, g, x, q, w, k;
    return n().wrap((function (e) {
      switch (e.prev = e.next) {
        case 0:
          return r = this.data.mode, e.next = 3, $.request["POST/user/new-update-get?source=XCX&mode=".concat(r, "&info=").concat(t)]();
        case 3:
          i = e.sent, d = a(i, 1), 200 === (o = d[0]).code ? (s = o.content, c = s.tel, l = s.desc, m = s.rent_days, f = s.wanted_num, h = s.manufacture_limit, p = s.brand_id, _ = s.model_id, y = s.class_id, b = s.address, v = s.province_id, g = s.city_id, x = s.latitude, q = s.longitude, w = s.payment_method, k = {
            address: b,
            city_id: g,
            latitude: x,
            longitude: q,
            province_id: v
          }, this.selectComponent("#form").setValues({
            address: k,
            tel: c,
            detail: l,
            rent_days: m,
            wanted_num: f,
            machine: {
              id: y[0].id,
              name: y[0].name
            },
            brand: p,
            model: _
          }), this.setData({
            factoryYearsValue: {
              id: h
            },
            machineValue: {
              id: y[0].id,
              name: y[0].name
            },
            payment_method: w
          })) : 14004 == o.code ? $.jxAlert({
            mode: "confirm",
            hideClose: !0,
            title: "温馨提示",
            content: o.msg,
            confirmText: "刷新信息"
          }).then((function () {
            u.reqInfoRefresh({
              mode: r,
              info: t
            }, !0)
          })).catch((function () {
            $.router.back()
          })) : $.jxAlert({
            content: o.msg
          });
        case 7:
        case "end":
          return e.stop()
      }
    }), e, this)
  })))).apply(this, arguments)
}
Page({
  useStore: function (e) {
    return {
      userInfo: e.storage.userInfo,
      machineConfig: e.global.machineConfig
    }
  },
  behaviors: [s.default],
  data: {
    mode: d.typeMode.seeking,
    recommendList: [],
    machineValue: null,
    factoryYearsList: d.factoryYears,
    factoryYearsValue: null,
    payment_method: "",
    array: ['日薪', '时薪'],
    index: 0,
    date:'',
    statusList: [{
      id: 1,
      name: "时薪"
    }, {
      id: 2,
      name: "日薪"
    }]
  },
  
  onLoad: function (e) {
   
  },
  createRent(){
    $.request['POST/business/engineering/publish']({
      
    }).then(res=>{

    })
  },
  onSubmit: (0, i.apply)(r(n().mark((function e() {
    var a, r, i, d, o, s, c, l, m, f, h, p, _, y, b;
    return n().wrap((function (e) {
      for (;;) switch (e.prev = e.next) {
        case 0:
          return e.next = 7, this.selectComponent("#form").verify({
            engineeringName: [{
              required: !0,
              message: "请填写项目名称"
            }],
            address: [{
              required: !0,
              message: "请选择施工地点"
            }],
            engineeringOwnerName: [{
              required: !0,
              message: "请选择业主"
            }],
            excavatorOwnerName: [{
              required: !0,
              message: "请选择机械主"
            }],
            driverOwnerName: [{
              required: !0,
              message: "请选择驾驶员"
            }],
            excavatorRentAmount: [{
              required: !0,
              message: "请选择机械价格"
            }],
            driverSalaryAmount: [{
              required: !0,
              message: "请选择驾驶员价格"
            }],
            startDate: [{
              required: !0,
              message: "请选择开始日期"
            }]
          });
        case 2:
          if (r = e.sent, !this.data.isShowCode || r.code) {
            e.next = 5;
            break
          }
          return e.abrupt("return", void $.msg("请输入验证码"));
        case 5:
          if (r.detail && !((null === (a = r.detail) || void 0 === a ? void 0 : a.length) < 5)) {
            e.next = 7;
            break
          }
          return e.abrupt("return", void $.msg("描述说明必须大于5个字符"));
        case 7:
          r=e.sent,i = r.address,console.log(i),h = '';
          b = {
            engineeringName:r.engineeringName,
            engineeringOwnerName:r.engineeringOwnerName.name,
            engineeringOwnerPhone:r.engineeringOwnerName.id,
            excavatorOwnerName:r.excavatorOwnerName.name,
            excavatorOwnerPhone:r.excavatorOwnerName.id,
            driverOwnerName:r.driverOwnerName.name,
            driverOwnerPhone:r.driverOwnerName.id,
            checkoutType:r.checkoutType.id,
            excavatorRentAmount:r.excavatorRentAmount,
            driverSalaryAmount:r.driverSalaryAmount,
            transportAmount:r.transportAmount,
            startDate:r.startDate,
            endDate:r.endDate,
            provinceId: i.province_id,
            provinceText: i.province_text,
            cityText: i.city_text,
            cityId: i.city_id,
            longitude: i.longitude,
            latitude: i.latitude,
            place: i.address
          }, $.request['POST/business/engineering/publish'](b).then(res=>{
            
            res=res[0]
            if(res.code==20002){
              let pages =getCurrentPages()
              let prevpage = pages[pages.length - 2];
              prevpage.getList()
              $.msg("创建成功"), setTimeout((function () {
                $.router.back({
                  params: {
                    "page-type": "publish"
                  }
                })
              }), 2000)
            }else{
              wx.showToast({
                icon:"none",
                title: res.msg,
              })
            }
          }), e.next = 15;
          break;
        case 13:
          return e.next = 15, u.checkPayReleasePopup(_, (function (e) {
            e ? (y.pay_code = "10001", y.coin = f.push_consume_coin, u.sendMachineInfo(y)) : u.sendMachineInfo(y)
          }));
        case 15:
          o = e.sent,console.log(o), c = a(o, 1), l = c[0],console.log(l), 20002 == l.code ? ($.msg("发布成功"), setTimeout((function () {
            $.router.back({
              params: {
                "page-type": "publish"
              }
            })
          }), 2e3)) : $.jxAlert({
            mode: "confirm",
            hideClose: !0,
            title: "温馨提示",
            content: l.msg,
            cancelText: "知道了",
            confirmText: ""
          });
        case "end":
          return e.stop()
      }
    }), e, this)
  })))),
  onClickFactoryLabel: function (e) {
    var t = e.target.dataset.item,
      n = this.data.factoryYearsValue,
      a = n && n.id == t.id;
    this.setData({
      factoryYearsValue: a ? null : {
        id: t.id,
        name: t.name
      }
    })
  },
  bindPickerChange(e){
    this.setData({
      index: e.detail.value
    })
  },
  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
});